package com.gzu.shop.util;

import org.mindrot.jbcrypt.BCrypt;

/**
 * @author Clown
 */

// Bcrypt算法加密工具类
public class PasswordBcryptUtil {
    // 生成加密后的密码
    public static String encryptPassword(String plainPassword) {
        return BCrypt.hashpw(plainPassword, BCrypt.gensalt());
    }
    // 检查原始密码和加密后的密码是否相等
    public static boolean checkPassword(String plainPassword, String hashedPassword) {
        boolean checkpw = false;
        try {
            checkpw = BCrypt.checkpw(plainPassword, hashedPassword);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return checkpw;
    }
}
